<template>
  <div class="home-container">
    <div class="banner">
      <div class="banner-content">
        <h1>欢迎来到我的博客</h1>
        <p>分享技术、生活和思考</p>
      </div>
    </div>
    
    <div class="main-content">
      <div class="blog-list">
        <Spin v-if="loading" tip="加载中..." />
        <div v-else-if="blogs.length === 0" class="empty-state">
          <p>暂无博客文章</p>
        </div>
        <div v-else>
          <BlogCard v-for="blog in blogs" :key="blog.id" :blog="blog" />
        </div>
      </div>
      
      <div class="sidebar">
        <AuthorCard />
        <CategoriesList :useApi="true" />
        <TagsList :useApi="true" />
      </div>
    </div>  
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue'
import { Spin } from 'ant-design-vue'
import { useBlogStore } from '../stores/blog'
import BlogCard from '../components/BlogCard.vue'
import AuthorCard from '../components/AuthorCard.vue'
import CategoriesList from '../components/CategoriesList.vue'
import TagsList from '../components/TagsList.vue'

// 使用 Pinia store
const blogStore = useBlogStore()

// 博客文章数据
const blogs = ref([])
// 加载状态
const loading = ref(false)

// 获取博客文章列表
const fetchBlogs = async () => {
  try {
    loading.value = true
    const data = await blogStore.getArticles({ page: 1, pageSize: 3 })
    if (data && data.list) {
      blogs.value = data.list
    }
  } catch (error) {
    console.error('获取博客列表失败:', error)
  } finally {
    loading.value = false
  }
}

// 不再需要获取分类和标签列表，由组件自行获取

// 组件挂载时获取数据
onMounted(async () => {
  await fetchBlogs()
})
</script>

<style scoped lang="less">
.home-container {
  width: 100%;
  min-height: 100vh;
}

.banner {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  padding: 80px 0;
  text-align: center;
  position: relative;
  overflow: hidden;
}

.banner::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: url('') repeat;
}

.banner-content {
  position: relative;
  z-index: 1;
  max-width: 800px;
  margin: 0 auto;
}

.banner-content h1 {
  font-size: 2.8em;
  margin-bottom: 20px;
  font-weight: 700;
  letter-spacing: -0.5px;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.banner-content p {
  font-size: 1.3em;
  opacity: 0.9;
  margin-bottom: 0;
  text-shadow: 0 1px 5px rgba(0, 0, 0, 0.1);
}

.main-content {
  max-width: 1200px;
  margin: 0 auto;
  padding: 40px 20px;
  display: flex;
  gap: 40px;
}

.blog-list {
  flex: 3;
}

.sidebar {
  flex: 1;
  min-width: 260px;
}

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: #999;
}

@media (max-width: 768px) {
  .main-content {
    flex-direction: column;
    gap: 20px;
  }
  
  .sidebar {
    min-width: auto;
  }
}

/* 暗黑模式样式 */
:global(.dark-mode) {
  .banner {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
  }
  
  .banner::before {
    background: url('') repeat !important;
  }
}
</style>